﻿using System;
using System.Linq;
using System.Threading.Tasks;
using Abp.Authorization;
using Abp.Domain.Repositories;
using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Magicodes.WeChat.Authorization;
using Magicodes.WeChat.User;
using Magicodes.WeChat.Web.Models.WeChatUsers;

namespace Magicodes.WeChat.Web.Controllers
{
    [AbpAuthorize(WeChatPermissions.Roots_Tenants_WeChatUser)]
    public class WeChatUsersController : BaseController
    {
        private readonly IWeChatUserAppService _weChatUserAppService;
        //private readonly IRepository<Group, int> _groupRepository;
        public WeChatUsersController(
            IWeChatUserAppService weChatUserService
            //, IRepository<Group, int> groupRepository
        )

        {
            _weChatUserAppService = weChatUserService;
            //_groupRepository = groupRepository;
        }


        public ActionResult Index()
        {
            return View();
        }

        [AbpMvcAuthorize(WeChatPermissions.Roots_Tenants_WeChatUser_Create, WeChatPermissions.Roots_Tenants_WeChatUser_Edit)]
        public async Task<PartialViewResult> CreateOrEditModal(string id)
        {
            var output = await _weChatUserAppService.GetWeChatUserForEdit(id);
            var viewModel = new CreateOrEditWeChatUserModalViewModel(output);
            //ViewBag.GroupId = _groupRepository.GetAllList().Select(s => new SelectListItem()
            //{
            //    Value = s.Id.ToString(),
            //    Text = s.Name,
            //    Selected = s.Id == viewModel.WeChatUser.GroupId
            //});
            return PartialView("_CreateOrEditModal", viewModel);
        }

    }
}